from time import sleep
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.common.by import By

def testlogin(get_driver):
      driver = get_driver
      driver.implicitly_wait(10)
      WebDriverWait(driver,2).until(expected_conditions.presence_of_element_located((By.NAME,"account")))
      driver.find_element(By.NAME,"account").send_keys("admin")
      WebDriverWait(driver,2).until(expected_conditions.presence_of_element_located((By.NAME,'password')))
      driver.find_element(By.NAME,'password').send_keys('123456')
      WebDriverWait(driver,2).until(expected_conditions.element_to_be_clickable((By.ID,"submit")))
      driver.find_element(By.ID,"submit").click()
      sleep(5)
      WebDriverWait(driver,15).until(expected_conditions.presence_of_element_located((By.XPATH,'//*[@id="s-menu-1"]/button')))
      driver.find_element(By.XPATH,'//*[@id="s-menu-1"]/button/img').click()
      driver.switch_to.default_content()
      sleep(5)
      # WebDriverWait(driver,5).until(expected_conditions.frame_to_be_available_and_switch_to_it('iframe-1'))
      driver.switch_to.frame("iframe-1")
      sleep(5)
      driver.find_element(By.XPATH,'//*[@id="dashboard"]/div[2]/a').click()
      sleep(5)
      WebDriverWait(driver,5).until(expected_conditions.element_to_be_clickable((By.XPATH,"blocks")))
      driver.find_element(By.ID,"blocks").send_keys("订单列表")
      WebDriverWait(driver,5).until(expected_conditions.presence_of_element_located((By.ID,"title")))
      driver.find_element(By.ID,"title").send_keys("西安")
      WebDriverWait(driver,5).until(expected_conditions.presence_of_element_located((By.XPATH,'//*[@id="ajaxForm"]/table/tbody/tr[2]/td/div/div/div/button')))
      driver.find_element(By.XPATH,'//*[@id="ajaxForm"]/table/tbody/tr[2]/td/div/div/div/button').click()
      WebDriverWait(driver,5).until(expected_conditions.presence_of_element_located((By.XPATH,'//*[@id="ajaxForm"]/table/tbody/tr[2]/td/div/div/div/div/li[2]/button')))
      driver.find_element(By.XPATH,'//*[@id="ajaxForm"]/table/tbody/tr[2]/td/div/div/div/div/li[2]/button').click()
      WebDriverWait(driver,5).until(expected_conditions.presence_of_element_located((By.XPATH,'//*[@id="paramstype_chosen"]/a/span')))
      driver.find_element(By.XPATH,'//*[@id="paramstype_chosen"]/a/span').click()